import axios from 'axios';
import bus from 'common/bus.js';
import { Message } from 'element-ui'
import store from '@/store'
import { putPleaParamHook } from './pleaParam'
// import { getAdminToken } from '@/utils/auth'

const API_SERVER = window.API_SERVER === 'http://' ? '' : window.API_SERVER;

const service = axios.create({
    baseURL: API_SERVER,
    timeout: 1000 * 1000 *1000,
    // withCredentials: true,  // 全局发送 cookie
    headers: {  // 配置请求头
        'Content-Type': 'application/json',
    },
    
})

service.interceptors.request.use( config => {
    // if (store.getters.getIsLogin) {
    //     config.headers['Cookie'] = getAdminToken()
    //   }
    return config;
}, error => {
    console.log(error,'res');
    return Promise.reject(error);
})

// 返回数据
service.interceptors.response.use(response => {
    //上传 请求信息 笑了
    try{
        putPleaParamHook(response)
    } catch(e){
        // console.log(e)

    }
    if(response.status === 200){
        
        return response.data;
    }else if(response.status == 404){
        
        Message.error('error')
    }else{
        
    }

    
    

}, error => {
})

export default service;